package com.mnb.base.service.impl;

import com.mnb.common.utils.R;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.mnb.base.entity.CusDuty;
import com.mnb.base.mapper.CusDutyMapper;
import com.mnb.base.service.CusDutyService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CusDutyServiceImpl implements CusDutyService{

    @Resource
    private CusDutyMapper cusDutyMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return cusDutyMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional
    public R insert(CusDuty cusDuty) {
        String[] userIds = cusDuty.getUserIds();
        for (String userId : userIds){
            cusDuty.setUserId(userId);
            cusDutyMapper.insert(cusDuty);
        }
        return R.ok();
    }

    @Override
    public int insertSelective(CusDuty record) {
        return cusDutyMapper.insertSelective(record);
    }

    @Override
    public CusDuty selectByPrimaryKey(Long id) {
        return cusDutyMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(CusDuty record) {
        return cusDutyMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(CusDuty record) {
        return cusDutyMapper.updateByPrimaryKey(record);
    }

    @Override
    public R getList(CusDuty cusDuty) {
        List<CusDuty> list =  cusDutyMapper.getList(cusDuty);
        return R.ok(list);
    }

    @Override
    @Transactional
    public R update(CusDuty cusDuty) {
        Long[] ids = cusDuty.getIds();
        for (Long id : ids) {
            cusDutyMapper.deleteByPrimaryKey(id);
        }
        String[] userIds = cusDuty.getUserIds();
        for (String userId : userIds){
            cusDuty.setUserId(userId);
            cusDutyMapper.insert(cusDuty);
        }
        return R.ok();
    }

    @Override
    public R getDayList(CusDuty cusDuty) {
        List<CusDuty> list =  cusDutyMapper.getDayList(cusDuty);
        return R.ok(list);
    }

}
